package xjtu.se.articlecommunity.buser.articlemanage;

import org.springframework.web.bind.annotation.*;
import xjtu.se.articlecommunity.buser.articlemanage.dto.articleDto;
import xjtu.se.articlecommunity.buser.articlemanage.dto.at_tabDto;
import xjtu.se.articlecommunity.buser.articlemanage.dto.onlyTabDto;
import xjtu.se.articlecommunity.buser.articlemanage.dto.tabDto;
import xjtu.se.articlecommunity.common.Result;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/buser/articlemanage")
public class ArticleManageAPI {
    @Resource
    private ArticleManageService articleManageService;
    @GetMapping("/getAllArticleList")
    public Result getAllArticleMessage(articleDto dto){
        List<articleDto>  getAll=articleManageService.findAllArticle(dto);
        return Result.success((Object)getAll);
    }
    @PostMapping("/getlistbyID")
    public Result getListByID(@RequestBody articleDto dto){
        List<articleDto>  getListbyID=articleManageService.getListByID(dto);
        return Result.success((Object)getListbyID);
    }

    @PostMapping("/getlistbyTitle")
    public Result getListByTitle(@RequestBody articleDto dto){
        List<articleDto>  getListbyTitle=articleManageService.getListByTitle(dto);
        return Result.success((Object)getListbyTitle);
    }
    @PostMapping("/getlistbyStatus")
    public Result getListByStatus(@RequestBody articleDto dto){
        List<articleDto>  getListbyStatus=articleManageService.getListByStatus(dto);
        return Result.success((Object)getListbyStatus);
    }

    @PostMapping("/getarticletab")
    public Result getArticleTab(@RequestBody tabDto dto){
        List<tabDto> getTab=articleManageService.findTab(dto);
        return Result.success(getTab);
    }
    @PostMapping("/ifchecked")
    public Result ifChecked(@RequestBody articleDto dto){
        boolean checked=articleManageService.checkarticle(dto);
        return Result.success(checked);
    }
    @PostMapping("/deleteattab")
    public Result deletatab(@RequestBody at_tabDto dto){
        boolean deletetab=articleManageService.deleteTab(dto);
        return Result.success(deletetab);
    }
    @PostMapping("/changetab")
    public Result changetab(@RequestBody onlyTabDto dto){
        boolean changeTab=articleManageService.changeTab(dto);
        return Result.success(changeTab);
    }
    @PostMapping("/deletearticle")
    public  Result deletearticle(@RequestBody articleDto dto){
        boolean deletearticle=articleManageService.deletearticle(dto);
        return Result.success(deletearticle);
    }
    @PostMapping("/findcontent")
    public Result findContent(@RequestBody articleDto dto){
        List<articleDto> articleContent=articleManageService.findContent(dto);
        String content=articleContent.get(0).getA_html();
        return Result.success(content);
    }
    @PostMapping("/findtitle")
    public Result findTitle(@RequestBody articleDto dto){
        List<articleDto> articleTitle=articleManageService.findTitle(dto);
        String title=articleTitle.get(0).getA_title();
        return Result.success(title);
    }
}
